<?php
namespace Home\Controller;

class ShopPayController extends PayController {
	
	public function _init() {
		layout('shop');
		$this->setModelName("PartnerProduct");
		$this->setModelControllerName("Shop");
		$this->checkLogin();
	}
	
	/**
	 * 支付后的返回页面
	 * @param unknown $cfg
	 * @return Ambigous <string, mixed>
	 */
	protected function getBackUrl( $order ) {
		return U("ShopOrder/showOrder", "id=".$order['id']."&sid=".$this->sid);
	}
	
	/**
	 * 获得支付接口列表
	 * @return multitype:
	 */
	protected function getPayApiList() {
		$d = D("My/ProductPayApi");
		$produtPayApiLists = $d->where("pid=%d and is_deleted=0 and status=1", $this->pid)->getField("tag,name") or $produtPayApiLists = array(); // 获得商家设置的支付接口
		return $produtPayApiLists;
	}
	
	/**
	 * 获得接口配置 
	 * @param unknown $cid
	 * @param unknown $settlementModes
	 * @return array
	 */
	protected function getApiConfig( $cfg ) {
		// 获得支付接口
		$productPayApi = D("ProductPayApi")->where("pid=%d and tag='%s'", $this->pid, $cfg['paymentMethod'])->find(); // 获得支付方式配置
		$config = (array)unserialize($productPayApi['cfg']);
		if ( 'WxTenpay' == $cfg['paymentMethod']) { // 微信支付时读取开发者配置
			$wechat = M('Wechat')->where(array('pid'=>$this->pid, 'cid'=>0))->find();
			$config = array_merge($config, array('appid' => $wechat['appid'], 'appsecret'=> $wechat['appsecret']));
		}
		return $config;
	}
	
}